#include "TrueText/Config.h"
#include "DrawersBuilder.h"
#include "FontImpl.h"
#include "FontEffectOutlineImpl.h"
#include "FontEffectShadowImpl.h"
#include "TextDrawer.h"

namespace TrueText {

DrawersBuilder::DrawersBuilder(boost::shared_ptr<FontImpl> font)
	: font(font)
{ }

DrawersBuilder::DrawersBuilder(const DrawersBuilder& rhs)
	: font(rhs.font)
{ }

const DrawersBuilder& DrawersBuilder::operator=(const DrawersBuilder& rhs)
{
	if (&rhs == this)
		return *this;

	font = rhs.font;

	return *this;
}

DrawersBuilder::~DrawersBuilder()
{ }

std::vector<boost::shared_ptr<Drawer> > DrawersBuilder::Build() const
{
	std::vector<boost::shared_ptr<Drawer> > result;

	boost::shared_ptr<TextDrawer> textDrawer(new TextDrawer(font));

	if (font->Outline().IsEnabled())
	{
		boost::shared_ptr<Drawer> outline = font->Outline().getImpl()->CreateDrawer(font, textDrawer);
		textDrawer->SetBlendMode(BLEND_ALPHA_COMPOSE);
		result.push_back(outline);
	}
	else if (font->Shadow().IsEnabled())
		result.push_back(font->Shadow().getImpl()->CreateDrawer(textDrawer.get()));

	result.push_back(textDrawer);

	return result;
}

}